<script setup>
import { ref, defineAsyncComponent } from "vue";

// 使用异步组件懒加载优化性能
const DragonBoatFestival = defineAsyncComponent(() =>
  import("./components/DragonBoatFestival.vue")
);
const Zongzi = defineAsyncComponent(() => import("./components/Zongzi.vue"));
const DragonBoatRace = defineAsyncComponent(() =>
  import("./components/DragonBoatRace.vue")
);

const activeTab = ref("home");

function changeTab(tab) {
  activeTab.value = tab;
}
</script>

<template>
  <div class="app-container">
    <nav class="nav-menu">
      <div class="logo">🐉 端午节</div>
      <div class="nav-links">
        <button
          @click="changeTab('home')"
          :class="['nav-link', { active: activeTab === 'home' }]"
        >
          首页
        </button>
        <button
          @click="changeTab('zongzi')"
          :class="['nav-link', { active: activeTab === 'zongzi' }]"
        >
          包粽子
        </button>
        <button
          @click="changeTab('race')"
          :class="['nav-link', { active: activeTab === 'race' }]"
        >
          赛龙舟
        </button>
      </div>
    </nav>

    <main class="main-content">
      <transition name="fade" mode="out-in">
        <DragonBoatFestival v-if="activeTab === 'home'" key="home" />
        <Zongzi v-else-if="activeTab === 'zongzi'" key="zongzi" />
        <DragonBoatRace v-else-if="activeTab === 'race'" key="race" />
      </transition>
    </main>

    <footer class="site-footer">
      <p>© {{ new Date().getFullYear() }} 端午节特别活动 | 传承中华文化</p>
    </footer>
  </div>
</template>

<style>
:root {
  font-family: "Microsoft YaHei", Arial, sans-serif;
  line-height: 1.6;
  font-weight: 400;
  color-scheme: light;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: #f8f9fa;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%23ff9a3c' fill-opacity='0.1'%3E%3Cpath opacity='.5' d='M96 95h4v1h-4v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v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 0h9v-9h-9v9zm9-10v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9z'/%3E%3Cpath d='M6 5V0H5v5H0v1h5v94h1V6h94V5H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  text-decoration: none;
  color: #ff5252;
  transition: color 0.3s;
}

a:hover {
  color: #ff3636;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: 1.2;
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.nav-menu {
  background-color: #ff5252;
  color: white;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.8rem;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.nav-links {
  display: flex;
  gap: 15px;
}

.nav-link {
  background: none;
  border: none;
  color: white;
  font-size: 1.1rem;
  padding: 8px 15px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.nav-link:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.nav-link.active {
  background-color: white;
  color: #ff5252;
  font-weight: bold;
}

.main-content {
  flex: 1;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

/* 添加过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.site-footer {
  background-color: #333;
  color: #fff;
  text-align: center;
  padding: 15px;
  margin-top: 30px;
}

@media (max-width: 600px) {
  .nav-menu {
    flex-direction: column;
    gap: 15px;
  }

  .nav-links {
    width: 100%;
    justify-content: center;
  }
}
</style>